package sqite

import (
	"Readme/initialine"
	"Readme/model"
)

func Article(userId int) (art []model.Article, err error) {
	err = initialine.DB.Raw("SELECT  e.* FROM  article e LEFT JOIN ( SELECT focu_id FROM focu WHERE user_id = ? ) a ON e.user_id=a.focu_id   ORDER BY  good_num DESC", userId).Scan(&art).Error
	if err != nil {
		return []model.Article{}, err
	}
	return art, nil

}

func AddArticle(UserId int64, Title string, Content string, CType int, GoodNum int64) (art model.Article, err error) {
	art = model.Article{
		Title:   Title,
		Content: Content,
		CType:   CType,
		UserId:  UserId,
		GoodNum: GoodNum,
	}
	err = initialine.DB.Create(&art).Error
	if err != nil {
		return model.Article{}, err
	}
	return art, nil
}
